package com.golookon.dao;


import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.golookon.entity.Menu;





@Repository
@Transactional
public class MenuDaoImpl extends BaseDaoImpl implements MenuDao{

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public List<Menu> getAllMenus() throws DataAccessException {
		return findAll(Menu.class);
	}

	@Override
	public List<Menu> searchMenus(String searchTerm) throws DataAccessException {
		@SuppressWarnings("unchecked")
		List<Menu> result = em.createQuery("SELECT DISTINCT m FROM MenuItem mi JOIN mi.menu m WHERE mi.name LIKE '"+ searchTerm+"'").getResultList();
		return result;
	}
	

}
